/*
 *  Solve the longest increasing subsequence.
 *
 * */
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <vector>

using namespace std;

int main(int argc, const char *argv[])
{
    int n;
    vector<int> iArray;
    vector<int> tables;
    vector<int> result;
    cin >> n;
    iArray.clear();
    srand((unsigned)time(NULL));
    for (int i = 0; i < n; i++) {
        iArray.push_back(rand()%n);
        cout << iArray[i] << "\t\t";
    }
    cout << endl;
    for (int i = 0; i < iArray.size(); i++) {
        tables.push_back(i ? ((iArray[i] > iArray[i-1]) ? (tables[i-1]+1) : 1) : 1);
        cout << tables[i] << "\t\t";
    }
    cout << endl;

    int MaxIdx = 0, MaxVal = 0;
    int MinIdx = 0, MinVal = 0;

    // Get the max value and its index in the tables.
    for (int i = 0; i < tables.size(); i++) {
        if (tables[i] > MaxVal) {
            MaxVal = tables[i];
            MaxIdx = i;
        }
    }
    cout << "the max long is:" << MaxVal << endl;

    //  Get the max value array in the tables.
    result.assign(iArray.begin()+MaxIdx - (MaxVal-1), iArray.begin()+MaxIdx + 1);
    for (int i = 0; i < result.size(); i++)
        cout << result[i] << "\t\t";
    cout << endl;

    return 0;
}
